<?php
class Getter_Controller extends Base_Controller
{

    public function action_index($needed)
    {

        $method = 'get_' . $needed;
        $html = '';
        $response = null;

        if (method_exists($this, $method)) {
            $html = call_user_func(array($this, $method));
        }

        if ($html) {
            $response = Response::json(compact('html'));
        } else {
            $response = Response::json(array('code' => -1), 500);
        }

        return $response;
    }


    private function get_districts ()
    {
        $data = City::find(Input::get('id'))->districts()->get();
        $html = "";
        foreach ($data as $item) {
            $html .= "<option value=\"{$item->id}\">{$item->district_name}</option>";
        }

        return $html;
    }

    private  function get_wards () {
        $data = District::find(Input::get('id'))->wards()->get();
        $html = '';
        foreach ($data as $item) {
            $html .= "<option value=\"{$item->id}\">{$item->ward_name}</option>";
        }

        return $html;
    }

    /**
     * Load điểm mốc theo Phường
     * POST extra -> get theo quận
     */
    private function get_anchors()
    {
        $anchors = array();
        if (Input::has('by_district')) {
            $anchors = Anchor::all_by_district(Input::get('id'));
        } else {
            $anchors = Anchor::all_by_ward(Input::get('id'));
        }

        return render('shared.anchor', compact('anchors'));

    }

    private function anchors_by_wards ($id)
    {
        $anchors = Ward::find($id);

    }

}